package Event;


import java.util.Vector;

public class MyEventRegister {
	protected Vector<MyEventListenerInterface> listenerList=new Vector<MyEventListenerInterface>();
	private int value;
	public void setValue(int newValue){
		if(value!=newValue){
			value=newValue;
			MyEvent evt=new MyEvent(newValue);
			fireMyEvent(evt);
		}
	}
	
	public synchronized void addMyEventListener(MyEventListenerInterface listener){
		listenerList.add(listener);
	}
	
	public synchronized void removedMyEventListener(MyEventListenerInterface listener){
		listenerList.removeElement(listener);
	}
	
	@SuppressWarnings("unchecked")
	public void fireMyEvent(MyEvent evt){
		Vector<MyEventListenerInterface> currentListenerList=null;
		synchronized(this){
			Vector<MyEventListenerInterface> clone = (Vector<MyEventListenerInterface>)listenerList.clone();
			currentListenerList=clone;
		}
		for(int i=0;i<currentListenerList.size();i++)
		{
			MyEventListenerInterface listener=(MyEventListenerInterface)currentListenerList.elementAt(i);
			listener.myEventOccurred(evt);
		}
	}
}